import
NXOpen
import
NXOpen.UF
import
NXOpen.Gateway
def
main():
theSession
=
NXOpen.Session.GetSession()
theUfSession
=
NXOpen.UF.UFSession.GetUFSession()
listWin
=
theSession.ListingWindow
basePart1
=
theSession.Parts.OpenBaseDisplay(
"c:/tmp/block.prt"
)
workPart
=
theSession.Parts.Work
unit1
=
workPart.UnitCollection.FindObject(
"MilliMeter"
)
p7
=
workPart.Expressions.FindObject(
"p7"
)
p8
=
workPart.Expressions.FindObject(
"p8"
)
p9
=
workPart.Expressions.FindObject(
"p9"
)
workPart.Expressions.EditWithUnits(p7, unit1,
"30"
)
workPart.Expressions.EditWithUnits(p8, unit1,
"60"
)
workPart.Expressions.EditWithUnits(p9, unit1,
"90"
)
theSession.UpdateManager.DoUpdate(
0
)
theBodyTags
=
[]
for
x
in
workPart.Bodies:
if
x.IsSolidBody:
theBodyTags.append(x.Tag)
sTLCreator1
=
theSession.DexManager.CreateStlCreator()
sTLCreator1.AutoNormalGen
=
True
sTLCreator1.ChordalTol
=
0.08
sTLCreator1.AdjacencyTol
=
0.08
sTLCreator1.OutputFile
=
"C:\\tmp\\block_ascii.stl"
sTLCreator1.OutputType
=
NXOpen.STLCreatorOutputTypeEnum.Text
body1
=
workPart.Bodies.FindObject(
"EXTRUDE(2)"
)
added1
=
sTLCreator1.ExportSelectionBlock.Add(body1)
nXObject1
=
sTLCreator1.Commit()
sTLCreator1.Destroy()
listWin.
Open
()
listWin.WriteLine(
"number of solid bodies: "
+
str
(
len
(theBodyTags)))
(massProps, Stats)
=
theUfSession.Modeling.AskMassProps3d(theBodyTags,
len
(theBodyTags),
1
,
4
, .
03
,
1
, [
0.99
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
,
0.0
])
listWin.WriteLine(
"units: kg, mm"
)
listWin.WriteLine(
"surface area: "
+
str
(massProps[
0
]))
listWin.WriteLine(
"volume: "
+
str
(massProps[
1
]
*
1E9
))
listWin.WriteLine(
"Hello, NXOpen"
)
listWin.Close()
theUI
=
NXOpen.UI.GetUI()
imageExportBuilder1
=
theUI.CreateImageExportBuilder()
custombackgroundcolor1
=
[
None
]
*
3
custombackgroundcolor1[
0
]
=
1.0
custombackgroundcolor1[
1
]
=
1.0
custombackgroundcolor1[
2
]
=
1.0
imageExportBuilder1.SetCustomBackgroundColor(custombackgroundcolor1)
imageExportBuilder1.FileFormat
=
NXOpen.Gateway.ImageExportBuilder.FileFormats.Png
imageExportBuilder1.FileName
=
"c:\\tmp\\block.png"
imageExportBuilder1.BackgroundOption
=
NXOpen.Gateway.ImageExportBuilder.BackgroundOptions.Original
imageExportBuilder1.EnhanceEdges
=
False
imageExportBuilder1.RegionMode
=
False
workPart.ModelingViews.WorkView.Fit()
nXObject6
=
imageExportBuilder1.Commit()
imageExportBuilder1.Destroy()
if
__name__
=
=
"__main__"
:
main()